<script>
function back(){
    window.location.href = <?php echo $_SERVER['HTTP_REFERER'] ?>;
}
</script>
<div style="text-align: center;">
<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */

function getSqlName($id){
	$query = System::$db->query("SELECT sql_name FROM {prefix}fields WHERE id ='".intval($id)."'");
	$data = $query->fetch_array();
	return $data[0];
}

if(!empty($_GET['id'])){
	
	if($_POST['delete'] == 'Smazat'){
		$query = $db->query("ALTER TABLE {prefix}fields_data DROP COLUMN ".getSqlName($_GET['id'])."");
		$query = $db->query("DELETE FROM {prefix}fields WHERE id = '".intval($_GET['id'])."'");
        $log->write(8, 'com_user', 'NOW()', 'User deleted field #'.intval($_GET['id']), $_SESSION['id']);
		$event = 'roar.alert(\'Status\', \'Pole bylo smazán !\');';
		array_push($Roar, $event);
		echo '<meta http-equiv="refresh" content="2;url=index.php?p=components&name=user&a=fields">';
	}else{
		echo '<h2>Opravdu chcete smazat pole #'.intval($_GET['id']).'  ?</h2>';
		echo '<form action="'.$_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'].'" method="post"><br />';
		echo '<input type="submit" name="delete" value="Smazat" />&nbsp;&nbsp;&nbsp;<input type="button" value="Zpět" onclick="back()" /></form>';
	}
}
?>
</div>